package com.com.cgq.data.exchenge;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.cgq.common.CellPhoneInfo;
import com.cgq.common.CommonFun;
import com.example.cgq.business.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by cgq on 2015/11/8.
 */
public class MainViewPage {

    private List<View> mViewList;
    private ViewPager mViewPager;
    private Context mContext;
    private List<String> mTitleList;
    private CellPhoneInfo mCellPhoneInfo;

    public MainViewPage(Context mContext, ViewPager mViewPager,CellPhoneInfo cellPhoneInfo) {
        initData();
        this.mViewPager = mViewPager;
        this.mContext = mContext;
        this.mCellPhoneInfo = cellPhoneInfo;
    }

    private void initData() {
        this.mCellPhoneInfo = new CellPhoneInfo();
    }

    public void setIsHideViewPage(boolean bIsShowViewPage) {
        if(bIsShowViewPage) {
            LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) mViewPager.getLayoutParams(); // 取控件mGrid当前的布局参数
            linearParams.height = 210;// 当控件的高强制设成50象素
            mViewPager.setLayoutParams(linearParams); // 使设置好的布局参数应用到控件myGrid
            mViewPager.setVisibility(View.VISIBLE);
        }else {
            mViewPager.setVisibility(View.GONE);
        }
    }



    public void initPageView() {

        mViewList = new ArrayList<>();
        View view1 = View.inflate(mContext, R.layout.main_page_1, null);
        View view2 = View.inflate(mContext, R.layout.main_page_2, null);
        View view3 = View.inflate(mContext, R.layout.main_page_3, null);
        View view4 = View.inflate(mContext, R.layout.main_page_4, null);

        Button imageView1 = (Button) view1.findViewById(R.id.id_pageView_image1);
        Button imageView2 = (Button) view1.findViewById(R.id.id_pageView_image2);
        Button imageView3 = (Button) view1.findViewById(R.id.id_pageView_image3);
        Button imageView4 = (Button) view1.findViewById(R.id.id_pageView_image4);

        CommonFun commonFun = new CommonFun();
        Log.d("tag", "initPageView: " + mCellPhoneInfo.ScreenWeight);
        commonFun.SetWeight(imageView1,mCellPhoneInfo.ScreenWeight/4);
        commonFun.SetWeight(imageView2,mCellPhoneInfo.ScreenWeight/4);
        commonFun.SetWeight(imageView3,mCellPhoneInfo.ScreenWeight/4);
        commonFun.SetWeight(imageView4,mCellPhoneInfo.ScreenWeight/4);


        mViewList.add(view1);
        mViewList.add(view2);
        mViewList.add(view3);
        mViewList.add(view4);


        mTitleList = new ArrayList<>();
        mTitleList.add("商品种类");
        mTitleList.add("稍后浏览");
        mTitleList.add("浏览历史");
        mTitleList.add("我的收藏");


        MainViewPageAdapter myViewPageAdapter = new MainViewPageAdapter(mViewList,mTitleList);
        mViewPager.setAdapter(myViewPageAdapter);
    }
}
